package logic

import (
	"context"
	"zg6/zg6_month/ordersrv/model"

	"zg6/zg6_month/ordersrv/internal/svc"
	"zg6/zg6_month/ordersrv/ordersrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type SaveOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSaveOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveOrderLogic {
	return &SaveOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SaveOrderLogic) SaveOrder(in *ordersrv.CreateOrderRes) (*ordersrv.CreateOrderRes, error) {
	// todo: add your logic here and delete this line
	order := new(model.Order)
	err := model.DB.Where("order_sn = ?", in.OrderSn).First(order).Error
	if err != nil {
		return nil, err
	}
	order.Status = 1
	return &ordersrv.CreateOrderRes{}, nil
}
